<?php

namespace app\common\model;

use think\Db;
use think\Model;

 /**
  * [Thirdparty 线下票务系统]
  * @Author   ZhouYunpeng
  * @DateTime 2020-04-27
  * @return   [type]      [description]
  */
class Thirdparty extends Model
{
    // 表名
    protected $name = 'thirdparty';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    
    public function getStatusList()
    {
        return ['normal' => __('Normal'),'hidden' => __('Locking')];
    }  

    public function getSystemList()
    {   

        $system =  Db::name('thirdparty_system')->select();
        $systemList = array_column($system,'system_name','id');
        return $systemList;
    }

    
    /**
     * [getScenicList 获取景区]
     * @Author   ZhouYunpeng
     * @DateTime 2020-04-28
     * @return   [type]      [description]
     */
    public function getScenicList()
    {   
        $scenic = Db::name('goods')
                  ->where(['g.store_id'=>\think\Session::get('store.id'),'s.status'=>1,'s.category_id'=>1])
                  ->where('s.delete_time','null')
                  ->alias('g')
                  ->join('scenic s','g.scenic_id = s.id','LEFT')
                  ->field('s.id,scenic_name')
                  ->select();
        $scenic_list =array_column($scenic,'scenic_name','id');
        return $scenic_list;
    }     


    public function scenic()
    {
        return $this->belongsTo('Scenic', 'scenic_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function system()
    {
        return $this->belongsTo('Thirdparty_system', 'system_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    /**
     * [delBindGoods 解除绑定第三方]
     * @Author   ZhouYunpeng
     * @DateTime 2021-10-28
     * @param    [type]      $goods_id [description]
     * @param    [type]                [description]
     */
    public function delBindGoods($goods_id)
    {
       Db::name('goods')->where(['id'=>$goods_id])->update(['bind_thirdparty'=>0]);
    }    
}
